package com.jiutong.meipengdai.http.present;

import android.content.Context;

import com.jiutong.meipengdai.entity.BaseRespond;
import com.jiutong.meipengdai.http.model.interfaces.PicUploadBiz;
import com.jiutong.meipengdai.http.model.requests.UserInfoRequest;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;

import java.util.HashMap;

/**
 * 作用:
 * Created by 78 on 2017/6/20.
 */

public class PicUploadPresent {

    private final Context mContext;
    private final PicUploadBiz picUploadBiz;
    private final UserInfoRequest userInfoRequest;

    public PicUploadPresent(Context context,PicUploadBiz picUploadBiz) {
        this.mContext = context;
        this.picUploadBiz = picUploadBiz;
        this.userInfoRequest = new UserInfoRequest();
    }

    /**
     * 图片上传
     */
    public void picUpload() {

        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BaseRespond>() {
            @Override
            public void onNext(BaseRespond subjects) {
                picUploadBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                picUploadBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("fileType",picUploadBiz.getFileType());
        fieldsMap.put("uploadType",picUploadBiz.getUploadType());
        fieldsMap.put("fileContent",picUploadBiz.getFileContent());
        fieldsMap.put("operatorId",picUploadBiz.getOperatorId());
        userInfoRequest.picUpload(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }


}
